package testdatagenerator;


public class GeneralData {
	private static GeneralData data = null;
	private int nodes, perRow, ttl, attacks, trans;
	private double stdDev, mean, dropRate, Vtime;
	
	//implements a variant of singleton that does not treat this like global data
	public static GeneralData getGeneralData(){
		if (data==null){
			data = new GeneralData();
			return data;
		} else {
			return null;
		}
	}
	
	private GeneralData(){
		nodes = 20;
		perRow = 5;
	}
	
	public double getDropRate(){
		return dropRate;
	}
	
	public double getVtime(){
		return Vtime;
	}
	
	public void decTrans(){
		trans--;
	}
	
	public int getTrans(){
		return trans;
	}
	
	public int getAttacks(){
		return attacks;
	}
	
	public int getNodes(){
		return nodes;
	}
	
	public int getPerRow(){
		return perRow;
	}
	
	public double getStdDev(){
		return stdDev;
	}
	
	public double getMean(){
		return mean;
	}
	
	public int getTTL(){
		return ttl;
	}
	
	public void setDropRate(double d) throws FieldException{
		if (d < 0 || d > 1){
			throw new FieldException("Drop rate");
		}
		dropRate = d;
	}
	
	public void setDropRate(String DropRate) throws FieldException{
		try{
			setDropRate(Double.parseDouble(DropRate));
		} catch(Exception exc){
			throw new FieldException("Time to live");
		}
	}
	
	public void setValidTime(double d) throws FieldException{
		if (d <= 0){
			throw new FieldException("Valid time");
		}
		Vtime = d;
	}
	
	public void setValidTime(String Validtime) throws FieldException{
		try{
			setValidTime(Double.parseDouble(Validtime));
		} catch(Exception exc){
			throw new FieldException("Valid time");
		}
	}
	
	//set roughly how many transmissions will occur
	public void setTrans(int x) throws FieldException{
		if (x < 1){
			throw new FieldException("Transmissions");
		}
		trans = x;
	}
	
	public void setTrans(String Trans) throws FieldException{
		try{
			setTrans(Integer.parseInt(Trans));
		} catch(Exception exc){
			throw new FieldException("Transmissions");
		}
	}
	
	public void setNumAttacks(int x) throws FieldException{
		if (x < 0){
			throw new FieldException("Number of attacks");
		}
		attacks = x;
	}
	
	public void setNumAttacks(String attacks) throws FieldException{
		try{
			setNumAttacks(Integer.parseInt(attacks));
		} catch(Exception exc){
			throw new FieldException("Number of attacks");
		}
	}
	
	public void setNodes(int Nodes) throws FieldException{
		if (Nodes <= 0){
			throw new FieldException("Number of nodes");
		}
		nodes = Nodes;
	}
	
	public void setNodes(String Nodes) throws FieldException{
		try{
			setNodes(Integer.parseInt(Nodes));
		} catch(Exception exc){
			throw new FieldException("Number of nodes");
		}
	}
	
	public void setPerRow(int PerRow, boolean IsPerRow) throws FieldException{
		if (PerRow <= 0 && IsPerRow){
			throw new FieldException("Per row");
		}
		perRow = PerRow;
	}
	
	public void setPerRow(String PerRow, boolean IsPerRow) throws FieldException{
		try{
			setPerRow(Integer.parseInt(PerRow), IsPerRow);
		} catch(Exception exc){
			if (IsPerRow){
				throw new FieldException("Nodes per row");
			} else {
				throw new FieldException("Graph density");
			}
		}
	}
	
	public void setStdDev(double StdDev) throws FieldException{
		if (StdDev < 0){
			throw new FieldException("Std dev");
		}
		stdDev = StdDev;
	}
	
	public void setStdDev(String StdDev) throws FieldException{
		try{
			setStdDev(Double.parseDouble(StdDev));
		} catch(Exception exc){
			throw new FieldException("Std dev of delay");
		}
	}
	
	public void setMean(double Mean) throws FieldException{
		if (Mean < 0) {
			throw new FieldException("Mean");
		}
		mean = Mean;
	}
	
	public void setMean(String Mean) throws FieldException{
		try{
			setMean(Double.parseDouble(Mean));
		} catch(Exception exc){
			throw new FieldException("Mean delay");
		}
	}
	
	public void setTTL(int TTL) throws FieldException{
		if (TTL < 1){
			throw new FieldException("Time to live");
		}
		ttl = TTL;
	}
	
	public void setTTL(String TTL) throws FieldException{
		try{
			setTTL(Integer.parseInt(TTL));
		} catch(Exception exc){
			throw new FieldException("Time to live");
		}
	}
	
}
